import Vue from 'vue'
import Router from 'vue-router'
import store from './store'
import Home from './views/Home.vue'
import Client from './views/Client.vue'
import ClientDetail from './views/ClientDetail.vue'
import Statistics from './views/Statistics.vue'
import Generalize from './views/Generalize.vue'
import Login from './views/Login.vue'
import UploadBf from './views/UploadBf.vue'

Vue.use(Router)


const router = new Router({
  routes: [
    { path: '/', redirect: '/home' },
    {
      path: '/home',
      name: 'home',//首页
      component: Home
    },
    {
      path: '/client',
      name: 'client',//客户
      component: Client
    },
    {
      path: '/clientDetail',
      name: 'clientDetail',//客户详情
      component: ClientDetail
    },
    {
      path: '/statistics',
      name: 'statistics',//统计
      component: Statistics
    },
    {
      path: '/generalize',
      name: 'generalize',//推广
      component: Generalize
    },
    {
      path: '/uploadBf',
      name: 'uploadBf',//上传记录
      component: UploadBf
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },

  ]
})
router.beforeEach((to, from, next) => {
  if (to.name !== 'login' && !store.state.userInfo.id) {
    return next({ path: '/login' });
  }
  next();
})

export default router;